home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-10-30 | 5.7 KB | 284 lines | [TEXT/CWIE] |
- { MainMenu.p }
- { Created 10/30/98 1:06 PM by AppMaker }
-
- Unit MainMenu;
- Interface
-
- Uses
- Types,
- Quickdraw,
- Controls,
- Dialogs,
- Events,
- Lists,
- LowMem,
- Menus,
- TextEdit;
-
- {----------}
- Procedure InitTitles;
- Procedure LoadMenus;
- Procedure DoMenu (menuChoice: longint);
- Procedure UpdateMenus;
-
- {----------}
- Implementation
-
- Uses
- Devices,
- Globals,
- ResourceDefs,
- Miscellany,
- AMApp,
- AMDoc,
- AMEngine,
- AMWindow;
-
- {----------}
- Function GetCommandFromMenu (
- menuChoice: longint): longint; Forward;
- Procedure DoApple (
- itemNr: integer); Forward;
-
- {----------}
- Procedure InitTitles;
- Begin
- end; {InitTitles}
-
- {----------}
- Procedure LoadMenus;
- Begin
- AppleMenu := GetMenu (MENU_Apple);
- FailNilResource (Handle (AppleMenu));
- AppendResMenu (AppleMenu, 'DRVR');
- FileMenu := GetMenu (MENU_File);
- EditMenu := GetMenu (MENU_Edit);
- PopupMenu := GetMenu (MENU_Popup);
- ModalMenu := GetMenu (MENU_Modal);
- ModelessMenu := GetMenu (MENU_Modeless);
- BevelMenu := GetMenu (MENU_Bevel);
-
- InsertMenu (AppleMenu, 0);
- InsertMenu (FileMenu, 0);
- InsertMenu (EditMenu, 0);
- InsertMenu (ModalMenu, 0);
- InsertMenu (ModelessMenu, 0);
-
- DrawMenuBar;
- end; {LoadMenus}
-
- {----------}
- Procedure DoMenu (
- menuChoice: longint);
- var
- commandID: longint;
- curDoc: AMDoc;
- menuID: integer;
- itemNr: integer;
- begin
- commandID := GetCommandFromMenu (menuChoice);
- curDoc := cur.mDoc;
- if cur.DoCommand (commandID) then begin
- { cur window handled it }
- end else if (curDoc <> nil)
- & (curDoc.DoCommand (commandID)) then begin
- { document handled it }
- end else if gApplication.DoCommand (commandID) then begin
- { application handled it }
- end else begin
- menuID := HiWrd (menuChoice);
- itemNr := LoWrd (menuChoice);
- if menuID = MENU_Apple then begin
- DoApple (itemNr);
- end;
- end;
- HiliteMenu (0);
- end; {DoMenu}
-
- {----------}
- Function GetCommandFromMenu (
- menuChoice: longint): longint;
- var
- commandID: longint;
- Begin
- commandID := 0;
-
- case menuChoice of
- cAppleAbout:
- commandID := cmdInvokeAbout;
- cFileNew:
- commandID := cmdNew;
- cFileOpen:
- commandID := cmdOpen;
- cFileClose:
- commandID := cmdClose;
- cFileSave:
- commandID := cmdSave;
- cFileSaveAs:
- commandID := cmdSaveAs;
- cFileRevert:
- commandID := cmdRevert;
- cFilePageSetup:
- commandID := cmdPageSetup;
- cFilePrint:
- commandID := cmdPrint;
- cFileQuit:
- commandID := cmdQuit;
- cEditUndo:
- commandID := cmdUndo;
- cEditCut:
- commandID := cmdCut;
- cEditCopy:
- commandID := cmdCopy;
- cEditPaste:
- commandID := cmdPaste;
- cEditClear:
- commandID := cmdClear;
- cEditSelectAll:
- commandID := cmdSelectAll;
- cEditShowClipboard:
- commandID := cmdShowClipboard;
- cModalButtons:
- commandID := cmdModalButtons;
- cModalCheckboxes:
- commandID := cmdModalCheckboxes;
- cModalRadios:
- commandID := cmdModalRadios;
- cModalText:
- commandID := cmdModalText;
- cModalStuff:
- commandID := cmdModalStuff;
- cModalMoreStuff:
- commandID := cmdModalMoreStuff;
- cModelessButtons:
- commandID := cmdModelessButtons;
- cModelessCheckboxes:
- commandID := cmdModelessCheckboxes;
- cModelessRadios:
- commandID := cmdModelessRadios;
- cModelessText:
- commandID := cmdModelessText;
- cModelessStuff:
- commandID := cmdModelessStuff;
- cModelessMoreStuff:
- commandID := cmdModelessMoreStuff;
-
- otherwise
- commandID := -menuChoice;
- end;
-
- GetCommandFromMenu := commandID;
- End;
-
- {----------}
- Procedure DoApple (
- itemNr: integer);
- var
- name: Str255;
- refNum: integer;
- Begin
- GetMenuItemText (AppleMenu, itemNr, name);
- refNum := OpenDeskAcc (name);
- End;
-
- {----------}
- var
- menu: MenuHandle;
- menuBarChanged: Boolean;
-
- {----------}
- Procedure Enable (
- itemNr: integer;
- enabled: Boolean);
- Begin
- if enabled then begin
- EnableItem (menu, itemNr);
- end else begin
- DisableItem (menu, itemNr);
- end;
- end; {Enable}
-
- {----------}
- Procedure EnableTitle (
- menu: MenuHandle;
- enabled: Boolean);
- Begin
- if enabled <> BTst (menu^^.enableFlags, 0) then begin
- menuBarChanged := true;
- end;
- if enabled then begin
- EnableItem (menu, 0);
- end else begin
- DisableItem (menu, 0);
- end;
- end; {EnableTitle}
-
- {----------}
- Procedure UpdateMenus;
- var
- frontPeek: WindowPeek;
- isFront: Boolean; {is there a front window?}
- isCur: Boolean; {is there a current window?}
- isCurDoc: Boolean; {is there a current document?}
- isDirty: Boolean; {is it dirty?}
- hasFile: Boolean; {does it have a file?}
- isSelected: Boolean; {is anything selected?}
- isDesk: Boolean; {is the front window a desk acc?}
- isText: Boolean; {is there a current text field?}
- isScrap: Boolean; {is there any scrap?}
- curTE: TEHandle;
- Begin
- menuBarChanged := false;
-
- isFront := (FrontWindow () <> nil);
- isCur := (curWindow <> nil);
- isDirty := false;
- hasFile := false;
- isSelected := false;
- isCurDoc := cur.mDoc <> nil;
- if isCurDoc then begin
- isDirty := cur.mDoc.mEngine.IsDirty;
- hasFile := cur.mDoc.mEngine.HasFile;
- end;
-
- isDesk := false;
- if isFront then begin
- frontPeek := WindowPeek (FrontWindow);
- isDesk := (frontPeek^.windowKind < 0);
- end;
-
- curTE := cur.GetCurTE;
-
- isText := isCur & (curTE <> nil);
- isScrap := false;
- if isText then begin
- isSelected := (curTE^^.selStart <> curTE^^.selEnd);
- isScrap := (TEGetScrapLength > 0);
- end;
-
- menu := FileMenu;
- Enable (cFileClose, isFront);
- Enable (cFileSave, isDirty);
- Enable (cFileSaveAs, isCurDoc);
- Enable (cFileRevert, isDirty);
-
- menu := EditMenu;
- if isFront then begin
- Enable (cEditUndo, isDesk);
- Enable (cEditCut, isDesk | isSelected);
- Enable (cEditCopy, isDesk | isSelected);
- Enable (cEditPaste, isDesk | isScrap);
- Enable (cEditClear, isDesk | isSelected);
- Enable (cEditSelectAll, isText);
-
- end;
- EnableTitle (EditMenu, isFront);
-
-
- if menuBarChanged then begin
- DrawMenuBar;
- end;
- end; {UpdateMenus}
-
- end.
-